<!-- 车型管理 -->
<template>
  <div class="dashboard-container car-models customer-list-box">
    <el-form
      ref="form"
      :inline="true"
      class="demo-form-inline"
    >
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="车型编号">
            <el-input
              v-model="form.id"
              placeholder="请输入车型编号"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="应载重量">
            <el-select
              v-model="form.allowableLoad"
              placeholder="请输入应载重量"
            >
              <el-option
                v-for="item in allowableLoadList "
                :key="item.value"
                :label="item.name"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="应载体积">
            <el-select
              v-model="form.allowableVolume"
              placeholder="请输入应载体积"
            >
              <el-option
                v-for="item in allowableVolumeList "
                :key="item.value"
                :label="item.name"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item label="车辆类型">
        <el-input
          v-model="form.name"
          placeholder="请输入车辆类型"
        ></el-input>
      </el-form-item>
      <el-form-item style="margin-left:40px">
        <el-button
          type="warning"
          @click="Search"
        >搜索</el-button>
      </el-form-item>
      <el-form-item>
        <el-button @click="Resetting">重置</el-button>
      </el-form-item>

    </el-form>

    <div class="demo-form-inline">
      <div style="margin-bottom:20px">
        <el-button
          type="warning"
          @click="add"
        >新增车型</el-button>
      </div>
      <el-table
        :data="list"
        style="width: 100%"
      >
        <el-table-column
          width="60"
          type="index"
          label="序号"
        >
        </el-table-column>

        <el-table-column
          width="200"
          prop="id"
          label="车型编号"
        >
        </el-table-column>
        <el-table-column
          width="140"
          prop="name"
          label="车辆类型"
        >
        </el-table-column>
        <el-table-column label="车辆数量">
          <template v-slot="{ row }">
            {{ row.num===null?0:row.num }}
          </template>
        </el-table-column>

        <el-table-column
          prop="allowableLoad"
          width="150"
          label="应载重量（吨）"
        >
        </el-table-column>
        <el-table-column
          prop="allowableVolume"
          width="150"
          label="应载体积（立方米）"
        >
        </el-table-column>
        <el-table-column
          prop="measureHigh"
          label="长（米）"
        > </el-table-column>
        <el-table-column
          prop="measureWidth"
          label="宽（米）"
        > </el-table-column>
        <el-table-column
          prop="measureHigh"
          label="高（米）"
        > </el-table-column>
        <el-table-column
          label="操作"
        >
          <template v-slot="{row}">
            <el-row
              style="margin-right:20px"
              type="flex"
              justify="space-around"
            >
              <el-col :span="6"><el-button
                size="mini"
                type="text"
                @click="edit(row.id)"
              >编辑</el-button></el-col>
              <el-col style="margin-left:10px"><div class="ww"></div></el-col>
              <el-col :span="6"><el-button
                size="mini"
                type="text"
                style="color:red"
                @click="del(row.id)"
              >删除</el-button></el-col>
            </el-row>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[10,20,30,40]"
          :page-size="form.pageSize"
          :current-page="form.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="count"
          @current-change="handleCurrentChange"
        >
        </el-pagination>
      </div>
    </div>
    <car-models-add
      :id="id"
      ref="edit"
      :dialog-visible.sync="dialogVisible"
      @Confirm="Confirm"
    ></car-models-add>
  </div>
</template>
<script>
import { list, add, update, del } from '@/api/transit'
import carModelsAdd from './components/car-models-add.vue'
export default {
  components: { carModelsAdd },
  data() {
    return {
      count: null,
      list: [],
      id: null,
      dialogVisible: false,
      form: {
        allowableLoad: '', // 重量
        allowableVolume: '', // 体积
        id: null, // id
        name: '', // 车辆类型
        page: 1, // 当前页码
        pageSize: 10 // 一页显示多少条
      },
      allowableLoadList: [
        {
          value: 'RANGE_LEVEL_1',
          name: '<1.8（吨）'
        },
        {
          value: 'RANGE_LEVEL_2',
          name: '1.8-6（吨）'
        },
        {
          value: 'RANGE_LEVEL_3',
          name: '6-14（吨）'
        },
        {
          value: 'RANGE_LEVEL_4',
          name: '14-30（吨）'
        },
        {
          value: 'RANGE_LEVEL_5',
          name: '30-50（吨）'
        },
        {
          value: 'RANGE_LEVEL_6',
          name: '50-100（吨）'
        },
        {
          value: 'RANGE_LEVEL_7',
          name: '100>（吨）'
        }
      ],
      // 搜索表单,应载体积数组
      allowableVolumeList: [
        {
          value: 'RANGE_LEVEL_1',
          name: '<3（m³）'
        },
        {
          value: 'RANGE_LEVEL_2',
          name: '3-5（m³）'
        },
        {
          value: 'RANGE_LEVEL_3',
          name: '5-10（m³）'
        },
        {
          value: 'RANGE_LEVEL_4',
          name: '10-15（m³）'
        },
        {
          value: 'RANGE_LEVEL_5',
          name: '15-30（m³）'
        },
        {
          value: 'RANGE_LEVEL_6',
          name: '30-50（m³）'
        },
        {
          value: 'RANGE_LEVEL_7',
          name: '50-80（m³）'
        },
        {
          value: 'RANGE_LEVEL_8',
          name: '80-150（m³）'
        },
        {
          value: 'RANGE_LEVEL_9',
          name: '150>（m³）'
        }
      ]
    }
  },
  created() {
    this.getCarTypeList()
  },
  methods: {
    del(id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        await del(id)
        this.getCarTypeList()
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },

    async edit(id) {
      this.id = id
      // const { data } = await detail(id)
      // console.log(data)
      this.$nextTick(() => {
        this.$refs.edit.detail()
      })

      this.dialogVisible = true
    },
    handleCurrentChange(v) {
      console.log(v)
      this.form.page = v
      this.getCarTypeList()
    },
    update(flag) {
      this.dialogVisible = flag
    },
    async Confirm(obj) {
      if (obj.id) {
        await update(obj.id, obj)
        this.$message.success('更新车辆成功')
      } else {
        await add(obj)
        this.$message.success('添加车辆成功')
      }

      this.getCarTypeList()
      this.dialogVisible = false
    },
    add() {
      this.dialogVisible = true
    },
    async getCarTypeList() {
      // const { data } = await getCarTypeList()
      // this.list = data
      const { data } = await list({ page: this.form.page, pageSize: this.form.pageSize })
      // console.log(res)
      this.count = +data.counts
      this.list = data.items
    },
    async Search() {
      const { data } = await list(this.form)
      // console.log(res)
      this.list = data.items
    },
    Resetting() {
      this.form.allowableLoad = ''
      this.form.allowableVolume = ''
      this.form.id = ''
      this.form.name = ''
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>

.ww {
    display: inline-block;
    width: 1px;
    height: 12px;
    background-color: #ccc;
    vertical-align: middle;

}
.block {
  display: flex;
  justify-content: center;
}
.demo-form-inline {
  margin: 25px;
  padding: 25px;
  background-color: #fff;
  border-radius: 5px;
}
.add-btn {
  margin-bottom: 20px;
}
.alert {
  margin: 10px 0px;
}
.pagination {
  margin-top: 40px;
  padding-bottom: 0px;
}

.el-select {
  width: 100%;
}

.car-models /deep/ .el-table td,
.el-table th {
  padding: 12px 0;
  min-width: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: left;
  overflow: hidden;
}
.car-models {
  /deep/ .el-dialog__title {
    width: 73px;
    height: 25px;
    font-size: 18px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    text-align: left;
    color: #20232a;
    line-height: 25px;
    letter-spacing: 0px;
  }
  /deep/ .el-dialog__body {
    text-align: center;
    padding: 40px 60px 0 30px;
  }
  .warn-img {
    width: 40px;
  }
  p {
    height: 24px;
    font-size: 16px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    color: #818693;
    line-height: 24px;
  }
}
</style>
